package com.funky.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * mybatisplus 自动添加字段配置类
 */
@Component
@Slf4j
public class MyMetaObjectHandler implements MetaObjectHandler {
  @Override
  public void insertFill(MetaObject metaObject) {
    log.info("start insert field....");
    this.setFieldValByName("createTime", new Date(),metaObject);
    this.setFieldValByName("updateTime", new Date(),metaObject);
    this.setFieldValByName("updateTime", new Date(),metaObject);
    this.setFieldValByName("member", 0,metaObject);
    this.setFieldValByName("member_id", "",metaObject);
    this.setFieldValByName("deleted", 0,metaObject);
    this.setFieldValByName("version", 1,metaObject);
  }

  @Override
  public void updateFill(MetaObject metaObject) {
    this.setFieldValByName("updateTime", new Date(),metaObject);
  }
}